package day03_ThreadPool.homework;

// MultiChoice 类
class MultiChoice extends Question {
    private final String[] options;
    private final char[] correctAnswers;

    public MultiChoice(String questionText, String[] options, char[] correctAnswers) {
        super(questionText);
        this.options = options;
        this.correctAnswers = correctAnswers;
    }

    @Override
    public boolean checkAnswer(Object answer) {
        if (answer instanceof char[]) {
            char[] userAnswers = (char[])answer;
            if (userAnswers.length != correctAnswers.length) {
                return false;
            }

            // 将答案排序后比较
            char[] sortedUser = userAnswers.clone();
            char[] sortedCorrect = correctAnswers.clone();

            java.util.Arrays.sort(sortedUser);
            java.util.Arrays.sort(sortedCorrect);

            return java.util.Arrays.equals(sortedUser, sortedCorrect);
        } else if (answer instanceof String) {
            String strAnswer = ((String)answer).toUpperCase();
            char[] userAnswers = strAnswer.toCharArray();
            return checkAnswer(userAnswers);
        }
        return false;
    }

    public String[] getOptions() {
        return options;
    }

    public char[] getCorrectAnswers() {
        return correctAnswers;
    }
}
